home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / pdisk.zip / FDINS.C < prev    next >
C/C++ Source or Header  |  1989-01-12  |  7KB  |  254 lines

  1. /* fdins: Install the FDTBL program for various systems.  See assembly
  2.  * source code for fdtbl at the bottom of this file.
  3.  *
  4.  * Copyright (C) 1986, 1988 Scott E. Garfinkle.  All rights reserved.
  5.  */
  6.  
  7. #include "part.h"
  8. #include <fcntl.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <io.h>
  12. #include <dos.h>
  13.  
  14. #pragma pack(1)
  15.  
  16. struct program {
  17.     word init_jump;
  18.     DISK_TABLE fdtbld;
  19.     byte unused1[24];
  20.     word intr_off;
  21.     byte unsused2[3];
  22.     word intr_seg;
  23.     byte unsed3[3];
  24.     byte diskno;
  25.     byte unused4[14];
  26. } *data;
  27.  
  28. byte data_tbl[] = {
  29.     0xEB, 0x10,
  30.     0x00, 0x04, 0x04, 0x00, 0x00, 0xff, 0xff, 0x00,
  31.     0x00, 0x00,    0x00, 0x00, 0x00, 0x04,    0x11, 0x00,
  32.     0xBE, 0x02, 0x01, 0xBF, 0x5C, 0x00, 0x8B, 0xC7, 0x8C, 0xCB, 0x8E, 0xC3,
  33.     0xB9, 0x08, 0x00, 0xFC, 0xF3, 0xA5, 0x33, 0xC9, 0x8E, 0xC1, 0x26, 0xA3,
  34.     0x04, 0x01,
  35.     0x26, 0x89, 0x1E,
  36.     0x06, 0x01,
  37.     0xB4, 0x09, 0xB2,
  38.     0x80,
  39.     0xCD, 0x13, 0xB4, 0x00, 0xCD, 0x13, 0xBA, 0x07, 0x00, 0xB8, 0x00, 0x31,
  40.     0xCD, 0x21
  41. };
  42.  
  43. #define DISK_NO1 0x80
  44. #define DISK_NO2 0x81
  45. #define DISK_NO1_LOC 0x41*4
  46. #define DISK_NO2_LOC 0x46*4
  47.  
  48. char *prgname = "tbl .com";
  49.  
  50. main(argc,argv)
  51. int argc;
  52. char **argv;
  53. {
  54.     int i, fd, line_no=4, num_disks;
  55.     union REGS regs;
  56.  
  57.     data = (struct program *)data_tbl;
  58.  
  59.     regs.h.ah = 8;
  60.     regs.h.dl = 0x80;
  61.     int86(0x13, ®s, ®s);
  62.     num_disks = regs.h.dl;
  63.  
  64.     scr_smode(scr_gmode());    /* quick way to clear screen */
  65.     scr_pos(22,0);
  66.     printf("Custom Fixed Disk Installation, Copyright(C) 1986, 1988 S. E. Garfinkle.");
  67.     scr_pos(23,0);
  68.     printf("All rights reserved.");
  69.     i = get_scr_val(line_no++,"Disk number 1 or 2?",1,1,2);
  70.     if (i == 1) {
  71.         data->diskno  = DISK_NO1;
  72.         data->intr_off = DISK_NO1_LOC;
  73.         data->intr_seg = DISK_NO1_LOC+2;
  74.     }
  75.     else {
  76.         data->diskno  = DISK_NO2;
  77.         data->intr_off = DISK_NO2_LOC;
  78.         data->intr_seg = DISK_NO2_LOC+2;
  79.     }
  80.     if (num_disks >= i)
  81.         data->fdtbld = *(DISK_TABLE far *) _dos_getvect(i==1 ? 0x41 : 0x46);
  82.     prgname[3] = i+'0';
  83.     data->fdtbld.fd_heads = get_scr_val(line_no++,"Number of heads on the disk?",data->fdtbld.fd_heads,0,72);
  84.     data->fdtbld.fd_ncyls = get_scr_val(line_no++,"Number of cylinders (max 1024)?",data->fdtbld.fd_ncyls,20,1024);
  85.     data->fdtbld.fd_control = get_scr_val(line_no++,"Control byte value?",0,0,0xff);
  86.     i = get_scr_val(line_no++,"Are you using an AT (0) or XT (1) compatible?",0,0,1);
  87.     data->fdtbld.fd_write_precomp = get_scr_val(line_no++,
  88.                   "Cylinder on which to start write precompensation?", i-1,-1,data->fdtbld.fd_ncyls-1);
  89.     if(i) {
  90.         data->fdtbld.fd_current = get_scr_val(line_no++,
  91.             "Cylinder on which to start write reduced write current?",data->fdtbld.fd_write_precomp,0,data->fdtbld.fd_ncyls-1);
  92.         data->fdtbld.fd_ecc_burst = get_scr_val(line_no++,"ECC Burst length?", 0x0b,0,0xff);
  93.         data->fdtbld.fd_std_time = get_scr_val(line_no++,"Standard timeout value?",0x0c,0,0xff);
  94.         data->fdtbld.fd_format_time = get_scr_val(line_no++,"Timeout value for formatting?",0xb4,0,0xff);
  95.         data->fdtbld.fd_check_time = get_scr_val(line_no++,"Timeout value for checks?",0x28,0,0xff);
  96.     }
  97.     else {
  98.         data->fdtbld.fd_lz = get_scr_val(line_no++,"Cylinder for landing zone?",data->fdtbld.fd_ncyls,0,2048);
  99.         data->fdtbld.fd_sec_per_track = get_scr_val(line_no++,"Number of sector per track?",data->fdtbld.fd_sec_per_track,1,40);
  100.     }
  101.     if((fd=open(prgname,O_CREAT|O_WRONLY|O_TRUNC|O_BINARY,S_IREAD|S_IWRITE)) < 0) {
  102.         fprintf(stderr,"\nCouldn't open %s file.\n",prgname);
  103.         exit(1);
  104.     }
  105.     write(fd,data_tbl,sizeof(struct program));
  106.     close(fd);
  107.     exit(0);
  108. }
  109.  
  110. #define ESC 27
  111. #define BACKSPACE 8
  112.  
  113. int
  114. get_scr_val(start, m_str, def_val, low_lim, high_lim)
  115. int start;        /* what line this goes on */
  116. char *m_str;    /* what to say on that line */
  117. int def_val,    /* default value */
  118.     low_lim,    /* least acceptable value */
  119.     high_lim;    /* highest acceptable value */
  120. {
  121.     int val, len, len1, len2, len3;
  122.     word pos, row, col, col2;
  123.     char buf[8];
  124.  
  125.     len1 = strlen(itoa(def_val, buf, 10));
  126.     len2 = strlen(itoa(low_lim, buf, 10));
  127.     len3 = strlen(itoa(high_lim, buf, 10));
  128.     len = max(max(len1,len2),len3);
  129.     scr_pos(start,0);
  130.     printf("%s  [%*s]",m_str,len," ");
  131.     fflush(stdout);
  132.     pos = scr_rpos();    /* read scr_pos position */
  133.     row = pos >> 8;
  134.     col2 = (pos & 0xff) - 2;
  135.     col = col2-len+1;
  136. #ifdef DEBUG
  137.     scr_pos(24,0); printf("len %d, row %d, col2 %d",len,row,col2);
  138.     fflush(stdout);
  139. #endif
  140.     do {
  141.         int c;
  142.  
  143.         val = 0;
  144.         do {
  145.             scr_pos(row, col);
  146.             printf("%*d",len,val ? val : def_val);
  147.             fflush(stdout);
  148.             scr_pos(row, col2);
  149.             c=getch();
  150. #ifdef DEBUG
  151. scr_pos(18,0);printf("!! val %d, c %d\n",val,c);fflush(stdout);
  152. #endif
  153.             switch (c) {
  154.             case '0':
  155.             case '1':
  156.             case '2':
  157.             case '3':
  158.             case '4':
  159.             case '5':
  160.             case '6':
  161.             case '7':
  162.             case '8':
  163.             case '9':
  164.                 if((val = val*10 + c - '0') > high_lim) {
  165.                     scr_pos(row+2,0);
  166.                     printf("Maximum value is %d.",high_lim);
  167.                     sleep(1000L);
  168.                     erase_eol(row+2);
  169.                     val = 0;
  170.                 }
  171.                 break;
  172.             case BACKSPACE:
  173.                 if(val)
  174.                     val /= 10;
  175.                 break;
  176.  
  177.             case EOF:
  178.                 exit(1);    /* assume we need an immediate abort */
  179.                 /* NOTREACHED */
  180.  
  181.             /* default: ignore the character. */
  182.  
  183.             } /* end of switch */
  184.         } while (c != '\r' && c != '\n' && c != ESC);
  185.         if(!val)
  186.             val = def_val;
  187.         else if (val<low_lim) {
  188.             scr_pos(row+2,0);
  189.             printf("Minimum value is %d.",low_lim);
  190.             sleep(1000L);
  191.             erase_eol(row+2);
  192.         }
  193.     } while(val<low_lim);
  194.     return(val);
  195. }
  196.  
  197. void
  198. erase_eol(from)    /* erase line "from" and stay there */
  199. word from;
  200. {
  201.     scr_scroll(from, 0, from, 79, 0, 7);
  202.     scr_pos(from,0);
  203. }
  204.  
  205. /*
  206. ; FDTBL:  Create fixed disk table to use instead of default DOS ones.
  207. ; This version can ONLY be used if you aren't going to use the Diagnostic
  208. ; routines -- these routines screw up the memory management and overwrite the
  209. ; table.  See accompanying program FDTBLINT if you're going to use the diags.
  210. ;
  211.     .RADIX    16
  212. INTR    EQU    (41*4)
  213. DISKNO    EQU    80
  214.  
  215. CSEG    SEGMENT
  216.     ORG    100
  217.     ASSUME    CS:CSEG,DS:CSEG
  218. BEGIN:    JMP    SHORT START
  219. DATA:    DW    400        ; number of cylinders
  220.     DB    4        ; number of heads
  221.     DW    -1        ; starting reduced write current cylinder (XT only)
  222.     DW    -1        ; starting write precompensation cylinder
  223.     DB    0        ; max ECC data burst length (XT only)
  224.     DB    0        ; control byte
  225.     DB    0        ; standard time out value (XT only)
  226.     DB    0        ; format time out value (XT only)
  227.     DB    0        ; check drive time out value (XT only)
  228.     DW    400    ; landing zone cyl (usually same as number of cyl)
  229.     DB    11        ; number of sectors per track (don't change)
  230.     DB    0        ; reserved
  231. START:    MOV    SI,OFFSET DATA
  232.     MOV    DI,5C
  233.     MOV    AX,DI
  234.     MOV    BX,CS
  235.     MOV    ES,BX
  236.     MOV    CX,8
  237.     CLD
  238.     REP     MOVSW
  239.     XOR    CX,CX
  240.     MOV    ES,CX
  241.     MOV    ES:[INTR],AX
  242.     MOV    ES:[INTR+2],BX
  243.     MOV    AH,9        ; "initialize characteristics"
  244.     MOV    DL,DISKNO
  245.     INT    13
  246.     MOV    AH,0        ; "reset disk"
  247.     INT    13
  248.     MOV    DX,7        ; retain 7 paragraphs -- first 70 hex bytes
  249.     MOV    AX,3100    ; terminate and stay resident
  250.     INT    21
  251. CSEG    ENDS
  252.     END    BEGIN
  253. */
  254.